import { isNull } from 'utils/ui-utils'

// const { moduleName } = require('env.cfg')

// const moduleCfg = window[moduleName]

// 空白填充
export function filterBlank(val) {
  return isNull(val) ? '-' : val;
}

// 加密身份证号码
export function transformIdCard(val) {
  if (val) {
    return `${val.substr(0, 4)}**********${val.substr(-4)}`;
  }
  return '';
}

export function filterNumbers(num) {
  return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
}

export function filterTimeToStr(val) {
  if (val) {
    const currentTime = Date.now()
    let minusTime = currentTime - new Date(val).getTime()
    minusTime = minusTime / 1000
    if (minusTime <= 60) {
      return `${Math.floor(minusTime)}秒前`
    }
    minusTime = minusTime / 60
    if (minusTime <= 60) {
      return `${Math.floor(minusTime)}分钟前`
    }
    minusTime = minusTime / 60
    if (minusTime <= 24) {
      return `${Math.floor(minusTime)}小时前`
    }
    minusTime = minusTime / 24
    if (minusTime <= 30) {
      return `${Math.floor(minusTime)}天前`
    }
    return val

  }
  return ''
}
